#include<bits/stdc++.h>
#define rg register
#define file(x)freopen(x".in","r",stdin);freopen(x".out","w",stdout)

using namespace std;

const int maxn=1e5+10;

int n;
vector<int>G[maxn];
inline void add(int x,int y)
{
	G[x].emplace_back(y);
	G[y].emplace_back(x);
}

int Ans=0;
priority_queue<pair<int,int>,vector<pair<int,int> >,less<pair<int,int> > >Q[maxn];
inline void dfs(int now,int fa)
{
	for(auto x:G[now])
		if(x^fa)
			dfs(x,now);
	for(auto x:G[now])
	{
		if(x==fa)continue;
		if(Q[now].size()<Q[x].size())swap(Q[now],Q[x]);
		while(!Q[x].empty())Q[now].emplace(Q[x].top()),Q[x].pop();
	}
	if(Q[now].size()==0)
	{
		Q[now].emplace(1,1);Ans=max(Ans,1);
		return;
	}
	if(Q[now].size()==1)
	{
		auto [x,y]=Q[now].top();Q[now].pop();
		x+=1,y^=1;Q[now].emplace(x,y);Ans=max(Ans,x);
		return;
	}
	auto tp1=Q[now].top();Q[now].pop();
	auto tp2=Q[now].top();Q[now].pop();
	int siz=tp1.first+tp2.first-2+tp1.second+tp2.second+1;
	if(tp1.second==0||tp2.second==0)siz+=1;
	Ans=max(Ans,siz);
	if(tp1.second==0&&tp2.second==0)
	{
		Q[now].emplace(siz,0);
		Q[now].emplace(1,1);
		return;
	}
	Q[now].emplace(siz,tp1.second&tp2.second);
}

int main()
{
	file("bird");
	scanf("%d",&n);
	for(rg int i=1;i<n;i+=1)
	{
		int x,y;scanf("%d %d",&x,&y);
		add(x,y);
	}
	dfs(1,0);
	printf("%d\n",Ans);
	return 0;
}
